/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * FormTipoHabitacion.java
 *
 * Created on 24/11/2010, 01:46:10 AM
 */

package pe.edu.upla.lamerced.desk.view.maestro;

import javax.swing.JDesktopPane;
import javax.swing.JOptionPane;
import pe.edu.upla.lamerced.Inicial;
import pe.edu.upla.lamerced.bean.Tipohabitacion;
import pe.edu.upla.lamerced.service.HabitacionService;

/**
 *
 * @author elvis
 */
public class FormTipoHabitacion extends javax.swing.JInternalFrame {

   private Tipohabitacion tipohabitacion;
   private JDesktopPane escritorio;
   private HabitacionService habitacionService;

    /** Creates new form FormTipoHabitacion */
    public FormTipoHabitacion() {
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
   // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
   private void initComponents() {

      jLabel1 = new javax.swing.JLabel();
      btnCancelar = new javax.swing.JButton();
      jLabel2 = new javax.swing.JLabel();
      jLabel3 = new javax.swing.JLabel();
      txtNombre = new javax.swing.JTextField();
      jScrollPane1 = new javax.swing.JScrollPane();
      txtdescripcion = new javax.swing.JTextArea();
      btnGrabar = new javax.swing.JButton();

      setClosable(true);
      setTitle("Tipo Hab itacion");

      jLabel1.setFont(new java.awt.Font("Arial", 0, 18)); // NOI18N
      jLabel1.setText("Tipo de Habitación");

      btnCancelar.setText("Cancelar");
      btnCancelar.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnCancelarActionPerformed(evt);
         }
      });

      jLabel2.setText("Nombre:");

      jLabel3.setText("Descripción:");

      txtdescripcion.setColumns(20);
      txtdescripcion.setRows(5);
      jScrollPane1.setViewportView(txtdescripcion);

      btnGrabar.setText("Grabar");
      btnGrabar.addActionListener(new java.awt.event.ActionListener() {
         public void actionPerformed(java.awt.event.ActionEvent evt) {
            btnGrabarActionPerformed(evt);
         }
      });

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                  .addGap(96, 96, 96)
                  .addComponent(btnGrabar)
                  .addGap(48, 48, 48)
                  .addComponent(btnCancelar))
               .addGroup(layout.createSequentialGroup()
                  .addGap(19, 19, 19)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jLabel2)
                     .addComponent(jLabel3))
                  .addGap(19, 19, 19)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                     .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 165, javax.swing.GroupLayout.PREFERRED_SIZE)
                     .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                           .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 226, javax.swing.GroupLayout.PREFERRED_SIZE)
                           .addComponent(txtNombre, javax.swing.GroupLayout.PREFERRED_SIZE, 181, javax.swing.GroupLayout.PREFERRED_SIZE))))
                  .addGap(19, 19, 19)))
            .addContainerGap())
      );
      layout.setVerticalGroup(
         layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
         .addGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addComponent(jLabel1)
            .addGap(21, 21, 21)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
               .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.LEADING)
               .addComponent(txtNombre, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            .addGap(18, 18, 18)
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
               .addGroup(layout.createSequentialGroup()
                  .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                  .addGap(19, 19, 19)
                  .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                     .addComponent(btnCancelar)
                     .addComponent(btnGrabar)))
               .addComponent(jLabel3))
            .addGap(14, 14, 14))
      );

      pack();
   }// </editor-fold>//GEN-END:initComponents

    private void btnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelarActionPerformed
       int res = JOptionPane.showConfirmDialog(this, "Seguro que desea cancelar la operacion?","Cancelar",JOptionPane.YES_NO_OPTION);
       System.out.println("resultado = " + res);
       cargaListaform();
       this.dispose();
    }//GEN-LAST:event_btnCancelarActionPerformed

    private void btnGrabarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnGrabarActionPerformed
       tipohabitacion.setNombre(txtNombre.getText().trim());
       tipohabitacion.setDetalle(txtdescripcion.getText().trim());
       habitacionService.registrarTipoHabitacion(tipohabitacion);
       JOptionPane.showMessageDialog(this, "El tipo de habitacion se ha registrado con exito");
       cargaListaform();
       this.dispose();
    }//GEN-LAST:event_btnGrabarActionPerformed
   public Tipohabitacion getTipohabitacion() {
      return tipohabitacion;
   }
   public void setTipohabitacion(Tipohabitacion tipohabitacion) {
      this.tipohabitacion = tipohabitacion;
   }
   public JDesktopPane getEscritorio() {
      return escritorio;
   }
   public void setEscritorio(JDesktopPane escritorio) {
      this.escritorio = escritorio;
   }
   public HabitacionService getHabitacionService() {
      return habitacionService;
   }
   public void setHabitacionService(HabitacionService habitacionService) {
      this.habitacionService = habitacionService;
   }


   // Variables declaration - do not modify//GEN-BEGIN:variables
   private javax.swing.JButton btnCancelar;
   private javax.swing.JButton btnGrabar;
   private javax.swing.JLabel jLabel1;
   private javax.swing.JLabel jLabel2;
   private javax.swing.JLabel jLabel3;
   private javax.swing.JScrollPane jScrollPane1;
   private javax.swing.JTextField txtNombre;
   private javax.swing.JTextArea txtdescripcion;
   // End of variables declaration//GEN-END:variables

   public void cargaInicial(){
       if(habitacionService==null){
         habitacionService = (HabitacionService)Inicial.getFactory().getBean("habitacionService");
      }
      txtNombre.setText(tipohabitacion.getNombre());
      txtdescripcion.setText(tipohabitacion.getDetalle());
   }

   public void cargaListaform(){
      ListaTipoHabitacion form = new ListaTipoHabitacion();
       form.setEscritorio(escritorio);
       form.cargaInicial();
       form.setVisible(true);
       escritorio.add(form);
   }

}
